#!/usr/bin/env python
#
#   Copyright (C) 2006 Jonathan Saggau                                    
#   saggau@gmail.com                                                      
#                                                                         
#   This program is free software; you can redistribute it and/or modify  
#   it under the terms of the GNU General Public License as published by  
#   the Free Software Foundation; either version 2 of the License, or     
#   (at your option) any later version.                                   
#                                                                         
#   This program is distributed in the hope that it will be useful,       
#   but WITHOUT ANY WARRANTY; without even the implied warranty of        
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         
#   GNU General Public License for more details.                          
#                                                                         
#   You should have received a copy of the GNU General Public License     
#   along with this program; if not, write to the                         
#   Free Software Foundation, Inc.,                                       
#   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  
#

import decoder

class NodeWatcher:
    decoder = decoder.Decoder()
    keys = ("/n_go", "/n_end", "/n_off", "/n_on", "/n_move", "/n_info")
    def __init__(self, controller):
        self.controller = controller
        
    def _none(self, msg):
        print "NONE"
        print msg
        
    def _decode(self, msg):
        return self.decoder.parseMsg(msg)
        
    def _go(self, msg):
        decoded = self._decode(msg)
        print "_go"
        self.decoder.printPretty(decoded)

    def _end(self, msg):
        decoded = self._decode(msg)
        print "_end" 
        self.decoder.printPretty(decoded)
        
    def _off(self, msg):
        decoded = self._decode(msg)
        print "_off" 
        self.decoder.printPretty(decoded)
        
    def _on(self, msg):
        decoded = self._decode(msg)
        print "_on" 
        self.decoder.printPretty(decoded)
        
    def _move(self, msg):
        decoded = self._decode(msg)
        print "_move" 
        self.decoder.printPretty(decoded)
        
    def _info(self, msg):
        decoded = self._decode(msg)
        print "_info" 
        self.decoder.printPretty(decoded)
        
def test():
    import scosc
    import synth
    import node
    import time
    ctl = scosc.Controller(('127.0.0.1', 57110))
    ctl.sendMsg('/dumpOSC', 1)
    watcher = NodeWatcher(ctl)
    ctl.listSendMsg(synth.new("JASSine", 1000, synth.HEAD, 1, {'freq':440}))
    time.sleep(2)
    ctl.listSendMsg(node.free(1000))

if __name__ == '__main__':
    test()